using MongoDB.Bson.Serialization;

namespace MongoScienceDAL.Core
{
    public class ScienceDatabaseClassMap
    {
        public static void RegisterTypes()
        {
            //Science type
            if (!BsonClassMap.IsClassMapRegistered(typeof(ScienceType)))
                BsonClassMap.RegisterClassMap<ScienceType>(cm =>
                    {
                        cm.AutoMap();
                        cm.GetMemberMap(x => x.Collection).SetElementName("col");
                        cm.GetMemberMap(x => x.Key).SetElementName("key");
                        cm.GetMemberMap(x => x.Name).SetElementName("name");
                        cm.GetMemberMap(x => x.Description).SetElementName("desc");
                        cm.GetMemberMap(x => x.Type).SetElementName("type");
                        cm.GetMemberMap(x => x.Settings).SetElementName("set");
                        cm.GetMemberMap(x => x.Index).SetElementName("index");
                        cm.GetMemberMap(x => x.Required).SetElementName("req");
                        cm.GetMemberMap(x => x.Hidden).SetElementName("hid");
                        cm.GetMemberMap(x => x.Readonly).SetElementName("ro");
                        cm.GetMemberMap(x => x.CreatedOn).SetElementName("con");
                        cm.GetMemberMap(x => x.CreatedBy).SetElementName("cby");
                    });

            //Collection type
            if (!BsonClassMap.IsClassMapRegistered(typeof(ScienceCollection)))
                BsonClassMap.RegisterClassMap<ScienceCollection>(cm =>
                    {
                        cm.AutoMap();
                        cm.GetMemberMap(x => x.Name).SetElementName("name");
                        cm.GetMemberMap(x => x.Description).SetElementName("desc");
                        cm.GetMemberMap(x => x.Index).SetElementName("index");
                        cm.GetMemberMap(x => x.CreatedOn).SetElementName("con");
                        cm.GetMemberMap(x => x.CreatedBy).SetElementName("cby");
                    });

            //ScienceFile
            if (!BsonClassMap.IsClassMapRegistered(typeof(ScienceFile)))
                BsonClassMap.RegisterClassMap<ScienceFile>(cm =>
                {
                    cm.AutoMap();
                    cm.GetMemberMap(x => x.FileId).SetElementName("fid");
                    cm.GetMemberMap(x => x.Filename).SetElementName("fn");
                    cm.GetMemberMap(x => x.UploadedBy).SetElementName("ub");
                    cm.GetMemberMap(x => x.UploadedOn).SetElementName("uo");
                    cm.GetMemberMap(x => x.Size).SetElementName("s");
                });

            //VersionedFile
            if (!BsonClassMap.IsClassMapRegistered(typeof(VersionedFile)))
                BsonClassMap.RegisterClassMap<VersionedFile>(cm =>
                {
                    cm.AutoMap();
                    cm.GetMemberMap(x => x.FileId).SetElementName("fid");
                    cm.GetMemberMap(x => x.Filename).SetElementName("fn");
                    cm.GetMemberMap(x => x.UploadedBy).SetElementName("ub");
                    cm.GetMemberMap(x => x.UploadedOn).SetElementName("uo");
                    cm.GetMemberMap(x => x.Size).SetElementName("s");
                    cm.GetMemberMap(x => x.Version).SetElementName("v");
                });
        }
    }
}